home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_bas / savbmp.zip / SAVBMP.FRM < prev    next >
Text File  |  1996-01-02  |  5KB  |  189 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   4356
  5.    ClientLeft      =   552
  6.    ClientTop       =   1428
  7.    ClientWidth     =   7488
  8.    Height          =   4956
  9.    Icon            =   SAVBMP.FRX:0000
  10.    Left            =   504
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4356
  13.    ScaleWidth      =   7488
  14.    Top             =   876
  15.    Width           =   7584
  16.    Begin CommandButton Command1 
  17.       Caption         =   "Write && Display new bitmap"
  18.       Height          =   375
  19.       Left            =   1320
  20.       TabIndex        =   1
  21.       Top             =   120
  22.       Width           =   2655
  23.    End
  24.    Begin CommonDialog CMDialog1 
  25.       CancelError     =   -1  'True
  26.       Filter          =   "bitmaps|*.bmp;*.dib;*.rle"
  27.       Left            =   2160
  28.       Top             =   0
  29.    End
  30.    Begin PictureBox Picture2 
  31.       AutoSize        =   -1  'True
  32.       Height          =   855
  33.       Left            =   3720
  34.       ScaleHeight     =   828
  35.       ScaleWidth      =   1428
  36.       TabIndex        =   2
  37.       Top             =   840
  38.       Width           =   1455
  39.    End
  40.    Begin PictureBox Picture1 
  41.       AutoRedraw      =   -1  'True
  42.       AutoSize        =   -1  'True
  43.       Height          =   1020
  44.       Left            =   132
  45.       Picture         =   SAVBMP.FRX:0302
  46.       ScaleHeight     =   83
  47.       ScaleMode       =   3  'Pixel
  48.       ScaleWidth      =   172
  49.       TabIndex        =   0
  50.       Top             =   840
  51.       Width           =   2088
  52.    End
  53.    Begin Menu MnuFile 
  54.       Caption         =   "File"
  55.       Begin Menu MnuFileOpen 
  56.          Caption         =   "Open"
  57.       End
  58.       Begin Menu MnuFileInfo 
  59.          Caption         =   "Info..."
  60.       End
  61.       Begin Menu Mnusep 
  62.          Caption         =   "-"
  63.       End
  64.       Begin Menu MnuFileExit 
  65.          Caption         =   "Exit"
  66.       End
  67.    End
  68.    Begin Menu MnuOptions 
  69.       Caption         =   "Options"
  70.    End
  71. End
  72. Option Explicit
  73.  
  74. 'output file name:
  75. Dim bmpfile$
  76. 'for the CMDialog:
  77. Const CANCELERR = 32755
  78.  
  79. Sub Command1_Click ()
  80.   Dim ans As Integer
  81.  
  82.   'Note: bmpfile$ is set in the form_load routine
  83.   ' to a default "test.bmp" in the app directory
  84.   If Form2!Option2(0) Then
  85.     'Create a disk file monochromatic bitmap
  86.     Call OutputMonoBmp(bmpfile$, Picture1)
  87.   ElseIf Form2!Option2(1) Then
  88.     'Create a disk file 16-color bitmap
  89.     Call Output16Bmp(bmpfile$, Picture1)
  90.   ElseIf Form2!Option2(2) Then
  91.     'Create a disk file 256-color bitmap
  92.     Call Output256Bmp(bmpfile$, Picture1)
  93.   Else
  94.     'Create a disk file 16-million color bitmap
  95.     Call Output24BitBmp(bmpfile$, Picture1)
  96.   End If
  97.   'Display it in the other picture box
  98.   Picture2.ZOrder
  99.   Picture2.Picture = LoadPicture(bmpfile$)
  100.  
  101. End Sub
  102.  
  103. Sub Form_Load ()
  104. ' keep the options form loaded at all times
  105.   Load Form2
  106. ' if picture1 has AutoRedraw, it needn't be visible
  107.   Picture1.AutoRedraw = True
  108.   'set output file name
  109.   bmpfile$ = App.Path & "\test.bmp"
  110.  
  111. End Sub
  112.  
  113. Sub Form_Unload (Cancel As Integer)
  114.   Unload Form2
  115.   End
  116. End Sub
  117.  
  118. Sub MnuFileExit_Click ()
  119.   Unload Me
  120. End Sub
  121.  
  122. Sub MnuFileInfo_Click ()
  123.   Dim h As Integer
  124. ' display info about bmp file
  125.   Dim FileHeader As BITMAPFILEHEADER
  126.   Dim InfoHeader As BITMAPINFOHEADER
  127.   Dim temp$
  128.  
  129.   On Error GoTo GetOut2
  130.   CMDialog1.Action = 1
  131.   
  132.   h = FreeFile
  133.   Open CMDialog1.Filename For Binary Access Read As #h
  134.   Get #h, , FileHeader
  135.   Get #h, , InfoHeader
  136.   Close #h
  137.   Form2!Frame2.Visible = False
  138.   Form2.Show
  139.   Form2.CurrentY = TextHeight("X")
  140.   Form2.Print " "; "Width:", , Str$(InfoHeader.biWidth)
  141.   Form2.Print " "; "Height:", , Str$(InfoHeader.biHeight)
  142.   Form2.Print " "; "Planes:", , Str$(InfoHeader.biPlanes)
  143.   Form2.Print " "; "Bits per pixel:", Str$(InfoHeader.biBitCount)
  144.   temp$ = " Uncompressed"
  145.   If InfoHeader.biCompression Then temp$ = " Run-length Encoded"
  146.   Form2.Print " "; "Compression:", temp$
  147.   temp$ = " All"
  148.   If InfoHeader.biClrUsed Then temp$ = Str$(InfoHeader.biClrUsed)
  149.   Form2.Print " "; "Colors Used:", , temp$
  150.   temp$ = " All"
  151.   If InfoHeader.biClrImportant Then temp$ = Str$(InfoHeader.biClrImportant)
  152.   Form2.Print " "; "Colors Important:", temp$
  153.  
  154. Exit Sub
  155. GetOut2:
  156. If Err <> CANCELERR Then MsgBox Error$(Err)
  157. Exit Sub
  158.  
  159. End Sub
  160.  
  161. Sub MnuFileOpen_Click ()
  162.  'load bitmap into picture1
  163.   On Error GoTo GetOut
  164.   CMDialog1.Action = 1
  165.   Picture1.Picture = LoadPicture(CMDialog1.Filename)
  166.   'make sure it's not covered by picture2!
  167.   Picture1.ZOrder
  168.   Exit Sub
  169. GetOut:
  170. If Err <> CANCELERR Then MsgBox Error$(Err)
  171. Exit Sub
  172.  
  173. End Sub
  174.  
  175. Sub MnuOptions_Click ()
  176.   Form2.Show 1
  177. End Sub
  178.  
  179. Sub Picture1_Click ()
  180. ' this should ensure that picture1's palette is
  181. ' realized when you click on it.
  182.   Picture1.ZOrder
  183. End Sub
  184.  
  185. Sub Picture2_Click ()
  186.   Picture2.ZOrder
  187. End Sub
  188.  
  189.